NeoX Integration
Overviewβ
GrantShares extends beyond Neo N3 to support cross-chain functionality with NeoX, an EVM-compatible sidechain. This integration enables the DAO to create and execute proposals on NeoX, bridging assets between Neo N3 and NeoX seamlessly.
The NeoX integration consists of three primary components:
- GrantSharesRelayer (Solidity) - Deployed on NeoX
- GrantSharesBridgeAdapter (neow3j) - Deployed on Neo N3
- Backend Event Monitor - Monitors NeoX events and triggers N3 transactions
Architectureβ
High-Level Flow Diagramβ
ββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ ββββββββββ βββββββ
β User/dApp β β NeoX β β Backend β β Neo N3 β
β β β β β β β β
β βββββ1ββββΆβ Relayer Contract β β β β β
β β propose β Emits Event βββββ2ββββΆβ Event Monitor β β β
β β β β β βββββ3ββββΆβ GrantSharesGovβ
β β β β β Calls N3 β β createProposalβ
β β β β β β β β
β β β β β β β β
β βββββ4ββββΆβ Relayer Contract β β β β [Voting...] β
β β execute β Emits Event βββββ5ββββΆβ Event Monitor β β β
β β β β β βββββ6ββββΆβ GrantSharesGovβ
β β β β β Calls N3 β β execute() β
β β β β β β β β β
β β β β β β β βΌ β
β β β β β β β Treasury β
β β β β β β β β β
β β β β β β β βΌ β
β β β β β β β BridgeAdapter β
β β β β β β β β β
β β β ββββββββββββββββββΌββββββββββΌββββββββββββββββββΌββββββββββ€ βΌ β
β ββββββ7ββββ Funds Received β β β β Neo X Bridge β
ββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββ
Flow Descriptionβ
Proposal Creation Flowβ
-
Event Emission on NeoX: User or dApp calls
propose()on theGrantSharesRelayercontract- Pays
proposalFeein ETH - Emits
CreateProposalevent with:sender: Address of proposer (indexed)proposal: Struct containingintents,offchainUri, andlinkedProposal
- Pays
-
Backend Captures Event: The backend's
ChainMonitorServicemonitors NeoX blocks- Listens for
CreateProposalevents using Web3j event filtering - Validates the event data via
EvmEventValidatorService - Extracts proposal data including
offchainUri(GitHub issue URL) andlinkedProposalID
- Listens for
-
Backend Calls N3 Contract: The
NeoTransactionServicecreates and sends a transaction- Calls
createProposal()on theGrantSharesGovcontract - Parameters: proposer address, intents, offchainUri, linkedProposal
- Uses backend account credentials for signing
- Proposal enters standard GrantShares voting workflow
- Calls
Proposal Execution Flowβ
-
Event Emission on NeoX: User or dApp calls
execute()on theGrantSharesRelayercontract- Pays
executionFeein ETH - Emits
ExecuteProposalevent with:proposalId: On-chain ID of proposal to execute (indexed)
- Pays
-
Backend Captures Event: The backend's
ChainMonitorServicemonitors NeoX blocks- Listens for
ExecuteProposalevents - Validates the event and retrieves the corresponding proposal from database
- Verifies proposal is in
Acceptedstate and ready for execution
- Listens for
-
Backend Calls N3 Contract: The
NeoTransactionServiceexecutes the proposal- Calls
execute()on theGrantSharesGovcontract with the proposal ID - Uses special signers configuration:
AccountSigner.none(backendAccount)- Backend accountContractSigner.calledByEntry(BridgeAdapter)- Allows bridge adapter to call GAS/NEO contracts
- The execution triggers the proposal's intents in sequence:
- Calls
-
Funds Transfer and Bridging:
- Treasury Transfer: Tokens move from
GrantSharesTreasurytoGrantSharesBridgeAdapter - Bridge Call: The adapter calls
bridge(token, to, amount):- Validates token type (GAS or NEO only)
- Checks balance is sufficient for amount + bridge fees
- Calls the Neo X Bridge contract:
depositNative()for GAS tokensdepositToken()for NEO tokens
- Validates no excess tokens remain (except up to
maxFeefor GAS)
- Bridge Processing: Neo X Bridge ensures funds arrive at the recipient's NeoX address
- Recipient Receives: Funds become available on the NeoX address specified in the proposal
- Treasury Transfer: Tokens move from
Componentsβ
1. GrantSharesRelayer (NeoX - Solidity)β
The GrantSharesRelayer is an upgradeable Solidity contract deployed on NeoX that serves as an event emitter and fee gate for cross-chain proposals.
Key Features:
- Event-based Architecture: Emits events captured by the backend for relay to Neo N3
- Fee System: Requires payment of configurable fees to prevent spam
- Pausable: Can be paused by the contract owner in case of emergencies
- Upgradeable: Uses UUPS (Universal Upgradeable Proxy Standard) upgrade pattern